// 03myCenter/02sectorization/06invitation/invitation.js
var co = require('../../../resource/js/common.js')
var app = getApp()
var _this

Page({
    data: {
        vip: [],                //我的会员列表
        isHidden: true,
        index: [],            //低级级下拉列表
        referrerInfo: '',      //推荐人信息
        userInfo: ''
    },
    onLoad: function (options) {
        _this = this;
        var user = app.Data.userInfo;
        this.getMyVip(user.User_ID, 0)
        this.setData({
            userInfo: user
        })
        this.getreferrerInfo(user.Owner_Id)
    },
    //我的推荐人信息
    getreferrerInfo: function (Oid) {
        var param = { User_ID: Oid }
        co.getShareApi('user/Mg/idGetInfo', param, function (res) {
            if (res.code == 0) {
                _this.setData({ referrerInfo: res.data })
            }
        })
    },
    //跳转到聊天界面
    tochat: function (e) {
        var User_ID = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/03myCenter/02sectorization/06invitation/chat/chat?User_ID=' + User_ID,
        })
    },
    //我的下级会员列表
    getMyVip(id, leng) {
        var param = {
            User_ID: id
        };
        var list = this.data.vip
        co.getShareApi('user/Mg/listSub', param, function (res) {
            if (res.code == 0) {
                list[leng] = res.data
                _this.setData({ vip: list })
            } else if (res.code == 29300) {
                list[leng] = res.data
                _this.setData({ vip: list })
            }
        })
    },
    //   一级下拉列表
    pullDown: function () {
        var isHidden = _this.data.isHidden;
        this.setData({ isHidden: !isHidden });
    },
    //   二级下来列表
    twoPullDown: function (e) {
        var index = this.data.index,
            indexs = e.currentTarget.dataset.index,
            leng = e.currentTarget.dataset.leng,
            User_ID = e.currentTarget.dataset.id;
        if (index[leng - 1] == indexs) {
            index[leng - 1] = -1
            this.setData({ index: index });
        } else {
            var list = this.data.vip
            list[leng] = ''
            this.setData({ vip: list })
            index[leng - 1] = indexs
            this.setData({ index: index });
            this.getMyVip(User_ID, leng)
        }
    }
})